package com.test.tom;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.ui.activity.BaseGameActivity;

import java.io.IOException;

public class GameActivity extends BaseGameActivity {


    private static final int CAMERA_WIDTH = 750;
    private static final int CAMERA_HEIGHT = 480;
    private ResourceManager r;
    private Camera mCamera;
    SceneManager sceneManager;
    @Override
    public EngineOptions onCreateEngineOptions() {
        this.mCamera = new Camera(0,0,CAMERA_WIDTH,CAMERA_HEIGHT);
        return  new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR,new RatioResolutionPolicy(CAMERA_WIDTH,CAMERA_HEIGHT),this.mCamera);
    }

    @Override
    public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws IOException {
       // loadTextures();

        sceneManager = new SceneManager(this,mEngine,mCamera);
        sceneManager.loadSplashResources();
        pOnCreateResourcesCallback.onCreateResourcesFinished();
        r = ResourceManager.getInstance();

    }
    @Override
    public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws IOException {

        /*
        scene = new Scene();
        scene.setBackground(new Background(0, 0, 0));
        physicsWorld = new PhysicsWorld(new Vector2( 0,0), false);
        this.scene.registerUpdateHandler(physicsWorld);
        pOnCreateSceneCallback.onCreateSceneFinished(scene);
        createWalls();*/
        pOnCreateSceneCallback.onCreateSceneFinished(sceneManager.createSplashScene());

    }



    @Override
    public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) throws IOException {
         /*


*/      mEngine.registerUpdateHandler(new TimerHandler(3.0f,new ITimerCallback() {
            @Override
            public void onTimePassed(TimerHandler pTimerHandler) {
                mEngine.unregisterUpdateHandler(pTimerHandler);
                sceneManager.loadGameResources();
                sceneManager.createGameScene();
                sceneManager.setCurrentScene(SceneManager.AllScenes.GAME);
            }
        }));
        pOnPopulateSceneCallback.onPopulateSceneFinished();

    }
}
